#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 1e4 + 10;

int p[N], c[N], hc[N], ha[N];
int n;
bool st[N];

struct Edges{
    int a, b;
}e[N];

struct Family{
    int idx, c, ha, hc;

    bool operator< (const Family & f) const {
        double avg1 = ha * 1.0 / c;
        double avg2 = f.ha * 1.0 / f.c;
        if (avg1 != avg2) return avg1 > avg2;
        return idx < f.idx;
    } 
};

int find (int x) {
    if (p[x] != x) p[x] = find(p[x]);
    return p[x];
}

inline void solution() {
    cin >> n;
    int idx = 0;
    for (int i = 0; i < n; i ++ ) {
        int id, father, mother, k;
        cin >> id >> father >> mother >> k;
        if (father != -1) e[idx ++ ] = {id, father};
        if (mother != -1) e[idx ++ ] = {id, mother};
        for (int j = 0; j < k; j ++) {
            int child;
            cin >> child;
            e[idx ++ ] = {id, child};
        }
        st[id] = true;
        cin >> hc[id] >> ha[id];
    }
    for (int i = 0; i < N; i ++ ) p[i] = i, c[i] = 1;
    for (int i = 0; i < idx; i ++ ) {
        int a = e[i].a, b = e[i].b;
        int pa = find(a), pb = find(b);
        st[a] = st[b] = true;
        if (pa != pb) {
            if (pb > pa) swap(pa, pb);
            c[pb] += c[pa];
            hc[pb] += hc[pa];
            ha[pb] += ha[pa];
            p[pa] = pb;
       
        }   
    }

    vector<Family> res;
    for (int i = 0; i < N; i ++ )
        if (st[i] && p[i] == i) 
            res.push_back({i, c[i], ha[i], hc[i]});

    sort(res.begin(), res.end());
    cout << res.size() << endl;
    for (int i = 0; i < res.size(); i ++ ) {
        auto t = res[i];
        printf("%04d %d %.3lf %.3lf\n", t.idx, t.c, t.hc * 1.0 / t.c, t.ha * 1.0 / t.c);
    }
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}